package com.bit;

import com.bit.Model.User;
import com.bit.controller.UserController;
import com.bit.controller.UserController1;
import com.bit.controller.UserController2;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class App {
    public static void main(String[] args) {
        //1.得到spring上下文
        ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
        //2.得到UserController对象
        UserController1 userController1 = context.getBean("userController1", UserController1.class);
        //3.调用方法
        User user1 = userController1.getUser();
        System.out.println(user1);

        UserController2 userController2 = context.getBean("userController2", UserController2.class);
        //3.调用方法
        User user2 = userController2.getUser();
        System.out.println(user2);
        /*
        //1.得到spring上下文
        ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
        //2.得到UserController对象
        UserController userController = context.getBean("userController",UserController.class);
        //3.调用方法
        User user = userController.getUser();
        System.out.println(user);
        */
        /*
        //1.得到spring上下文
        ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
        //2.得到UserController对象
        UserController userController = context.getBean("userController",UserController.class);
        //3.调用方法
        User user = userController.findUserById(1);
        System.out.println(user);
        */

        /*
        //1.得到spring上下文
        ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
        //2.得到某个bean
        User user = (User) context.getBean("u1");
        //3.调用bean方法
        System.out.println(user);
        */

        /*
        //1.先获取对象的上下文
        ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
        //2.获得对象，id存入的默认规则是将类型的首字母小写
        UserController userController = context.getBean("userController" , UserController.class);
        userController.sayHi("java");

        UserService userService = context.getBean("userService" , UserService.class);
        userService.sayHi("python");

        UserRepository userRepository = context.getBean("userRepository" , UserRepository.class);
        userRepository.sayHi("C++");

        UserConfiguration userConfiguration = context.getBean("userConfiguration" , UserConfiguration.class);
        userConfiguration.sayHi("C");

        UserComponent userComponent = context.getBean("userComponent" , UserComponent.class);
        userComponent.sayHi("Go");
        */
    }
}
